<template>
	<fui-form>

		<custom-form-item-card>
			<fui-form-item label="暂停原因" label-width="auto" asterisk>
				<template #vertical>
					<fui-radio-group v-model="formData.reason">
						<fui-label v-for="item in reasonList" :key="item.value">
							<fui-list-cell>
								<view class="fui-align__center">
									<fui-radio :value="item.value"></fui-radio>
									<fui-text class="m-l-16" :text="item.label"></fui-text>
								</view>
							</fui-list-cell>
						</fui-label>
					</fui-radio-group>
				</template>
			</fui-form-item>
			<fui-form-item label="说明">
				<template #vertical>
					<fui-textarea v-model="formData.remark" :borderTop="false" placeholder="请输入"></fui-textarea>
				</template>
			</fui-form-item>
			<fui-form-item label="附件" :bottom-border="false">
				<template #right>
					<custom-button-upload @change="onUploadFile"></custom-button-upload>
				</template>
			</fui-form-item>
			<custom-file-list :list="fileList" @del="onDelFile"></custom-file-list>
		</custom-form-item-card>
	</fui-form>
</template>
<script>
	import {
		defineComponent
	} from "vue"
	import {
		mapState,
		mapWritableState,
		mapActions
	} from 'pinia'
	import {
		useHandleWorkOrder_Pause
	} from "../../../../store/modules/handleWorkOrder_Pause.js"
	import {
		useSyStemStore
	} from "../../../../store/modules/system"
	import {
		getDicValue
	} from "../../../../utils/util"
	import {
		DIC_KEY
	} from "../../../../config/dicKey-config"
	import form from '@/components/firstui/fui-validator/fui-validator'
	import _ from 'lodash'
	import {
		WorkOrderMyIndexApi
	} from "../../../../api/workOrder"
	export default defineComponent({
		data() {
			return {

			}
		},
		computed: {
			...mapWritableState(useHandleWorkOrder_Pause, ['formData', 'fileList']),
			...mapState(useSyStemStore, ['dicList']),
			reasonList() {
				return getDicValue(this.dicList, DIC_KEY.obs_pause_reason)
			},

		},
		emits: ['disabled'],
		methods: {
			...mapActions(useHandleWorkOrder_Pause, ['onDelFile', 'onUploadFile']),
			async submit(orderNum, cb) {
				const rules = [{
					name: "reason",
					rule: ["required"],
					msg: ["请选择暂停原因"]
				}];
				try {
					this.formData.orderNum = orderNum
					let {
						isPassed,
						errorMsg
					} = form.validator(this.formData, rules)
					if (isPassed) {
						this.$emit('disabled', true)
						await WorkOrderMyIndexApi.pause(this.formData)
						this.fui.toast('暂停成功!')
						_.delay(() => {
							this.formData = {
								reason: '',
								enclosure: [],
								remark: '',
								orderNum: '',
							}
							cb && cb()
						}, 500)
					} else {
						this.$emit('disabled', false)
						this.fui.toast(errorMsg)
					}
				} catch (err) {
					this.$emit('disabled', false)
					console.error(err);
					this.fui.toast(err)

				}
			}
		},
	})
</script>

<style>
</style>